import { notification } from 'antd';
import {
    getInterviewType,
    getInterviewMode,
    getPosition,
    getRank,
    getPeopleOld,
    getPeopleEdu,
    getPeopleYear,
    getPeopleSex
} from '@/services/recruitStat/process';

export default {
    namespace: 'process',
    state: {
        interviewType: [],
        interviewMode: [],
        position: [],
        rank: [],
        peopleOld: [],
        peopleEdu: [],
        peopleYear: [],
        peopleSex: []
    },
    effects: {
        // eslint-disable-next-line no-empty-function
        *getProcess({ payload }, { put, call, all }) {
            const [
                interviewType,
                interviewMode,
                position,
                rank,
                peopleOld,
                peopleEdu,
                peopleYear,
                peopleSex
            ] = yield all([
                call(getInterviewType, payload),
                call(getInterviewMode, payload),
                call(getPosition, payload),
                call(getRank, payload),
                call(getPeopleOld, payload),
                call(getPeopleEdu, payload),
                call(getPeopleYear, payload),
                call(getPeopleSex, payload)
            ]);
            if (interviewType.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        interviewType: interviewType.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${interviewType.msg}`
                });
            }
            if (interviewMode.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        interviewMode: interviewMode.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${interviewMode.msg}`
                });
            }
            if (position.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        position: position.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${position.msg}`
                });
            }
            if (rank.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        rank: rank.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${rank.msg}`
                });
            }
            if (peopleOld.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        peopleOld: peopleOld.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${peopleOld.msg}`
                });
            }
            if (peopleEdu.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        peopleEdu: peopleEdu.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${peopleEdu.msg}`
                });
            }
            if (peopleYear.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        peopleYear: peopleYear.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${peopleYear.msg}`
                });
            }
            if (peopleSex.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        peopleSex: peopleSex.data
                    }
                });
            } else {
                notification.error({
                    message: `请求错误 ${peopleSex.msg}`
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        },
        clear(state) {
            return {
                ...state,
                interviewType: [],
                interviewMode: [],
                position: [],
                rank: [],
                peopleOld: [],
                peopleEdu: [],
                peopleYear: [],
                peopleSex: []
            };
        }
    }
};
